<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>登录</title>
	<link rel="stylesheet" href="/static/dependency/js/bootstrap-3.3.7/css/bootstrap.css">
	<link rel="shortcut icon" type="image/x-icon" href="/static/dependency/pic/logo.ico"/>
	<script src="/static/dependency/js/jquery-3.2.1.min.js"></script>
	<script src="/static/dependency/js/bootstrap-3.3.7/js/bootstrap.js"></script>
	<style>
		h1{
			color: #2B91AF;
		}
		#form_panel{
			padding: 10px;
			border:2px solid transparent;
			box-shadow:0 0 16px #888888;
			background-color: #ffffff;
		}
		body{
			background-color: #e8edf3;
		}
		#username_scope, #passwd_scope, #passwd_scope_confirm{
			width: 100%;
		}
	</style>
</head>
<body>
<div class="container">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<div class="page-header">
				<h1>
					Sora Web Terminal v0.1
				</h1>
				<h5>
					Copyright © 2017 Hochikong. All rights reserved.
				</h5>
			</div>
		</div>
	</div>
	<div class="row clearfix">
		<div class="col-md-4 column">
			<!--空-->
		</div>
		<div class="col-md-4 column">
			<div id="form_panel">
				<img src="/static/dependency/pic/readyforuse.png" alt="Sora:Web Terminal">
				<hr style="height:5px;border:none;border-top:1px solid #677077;" />
				<p>用户名:</p>
				<input type="text" name="username" id="username_scope" value="Admin" disabled="disabled">
				<br/>
				<br/>
				<p>密码:</p>
				<input type="password" name="password" id="passwd_scope">
				<br/>
				<br/>
				<p>请再次输入密码:</p>
				<input type="password" name="password" id="passwd_scope_confirm">
				<br/>
				<br/>
				<hr style="height:5px;border:none;border-top:1px solid #677077;" />
				<button type="button" class="btn btn-primary btn-default btn-block" id="create">创建</button>
			</div>
		</div>
		<div class="col-md-4 column">
			<!--空-->
		</div>
	</div>
</div>
<script>
	jQuery(document).ready(function () {
		jQuery("#create").click(function () {
			var username = jQuery("#username_scope").val();
			var passwd = jQuery("#passwd_scope").val();
			var passwdconfirm = jQuery("#passwd_scope_confirm").val();
			if(passwd.length > 0 && passwd == passwdconfirm){
			    var register_data = {"username":username,"passwd":passwd};
			    jQuery.ajax({
                type: 'POST', url: '/firstreg',
                data: JSON.stringify(register_data),
                contentType: 'application/json; charset=UTF-8',
                dataType: 'json',
                success: function (response) {
                    if(response.status == 'ok'){
                        window.location.href='/'
                    }
                    else{
                        alert(response.msg);
                        jQuery("#passwd_scope").val("");
	                    jQuery("#passwd_scope_confirm").val("").focus();
                    }
                }
            })
			}
			else{
			    alert('错误！两次输入的密码不正确');
			    jQuery("#passwd_scope").val("");
				jQuery("#passwd_scope_confirm").val("").focus();
			}
        })
    })
</script>
</body>
</html>